import mockApi from "@/api/mockApi";
import type {TrainingRecordForm} from '@/types/req/trainingRecordForm'
import type {TrainingRecordQueryForm} from '@/types/req/trainingRecordQueryForm'
import type {TrainingRecord} from '@/types/resp/trainingRecord'
import type {Response} from '@/types/response'
import type {Result} from '@/types/result'
import type {Page} from "@/types/page";
import dayjs from "dayjs";

export default class trainingRecordApi {
  static trainingRecords: TrainingRecord[] = [
    {"id":1,"employeeId":4,"employeeName":"陈静","trainingName":"高级项目管理培训","trainingDate":dayjs("2023-05-15"),"durationHours":8,"provider":"PMI（项目管理协会）","trainingDescription":"深入学习项目管理方法论，提升项目规划与执行能力","createTime":"2024-01-14 22:24:16","modifyTime":"2024-07-23 22:24:16"},
    {"id":2,"employeeId":2,"employeeName":"李娜","trainingName":"数据分析与可视化","trainingDate":dayjs("2023-06-20"),"durationHours":6,"provider":"Google","trainingDescription":"学习数据分析工具（如Python、Tableau）的使用，掌握数据可视化技巧","createTime":"2024-11-02 22:24:16","modifyTime":"2024-08-31 22:24:16"},
    {"id":3,"employeeId":4,"employeeName":"陈静","trainingName":"云计算架构设计","trainingDate":dayjs("2023-03-10"),"durationHours":12,"provider":"亚马逊云科技（AWS）","trainingDescription":"学习AWS云服务架构设计，掌握高可用性与可扩展性设计原则","createTime":"2024-04-18 22:24:16","modifyTime":"2024-01-30 22:24:16"},
    {"id":4,"employeeId":4,"employeeName":"陈静","trainingName":"敏捷开发实践","trainingDate":dayjs("2023-09-05"),"durationHours":4,"provider":"Scrum Alliance","trainingDescription":"学习敏捷开发流程与Scrum框架，提升团队协作与交付效率","createTime":"2024-06-30 22:24:16","modifyTime":"2024-05-18 22:24:16"},
    {"id":5,"employeeId":3,"employeeName":"王强","trainingName":"网络安全基础","trainingDate":dayjs("2023-11-01"),"durationHours":8,"provider":"Cisco","trainingDescription":"学习网络安全基础知识，掌握常见攻击防御与网络安全管理","createTime":"2024-03-27 22:24:16","modifyTime":"2024-04-18 22:24:16"},
    {"id":6,"employeeId":4,"employeeName":"陈静","trainingName":"产品创新与用户体验设计","trainingDate":dayjs("2024-02-15"),"durationHours":6,"provider":"IDEO","trainingDescription":"学习产品创新方法与用户体验设计原则，提升产品设计能力","createTime":"2024-11-20 22:24:16","modifyTime":"2024-11-02 22:24:16"},
    {"id":7,"employeeId":3,"employeeName":"王强","trainingName":"DevOps实践与工具","trainingDate":dayjs("2023-07-22"),"durationHours":10,"provider":"微软","trainingDescription":"学习DevOps文化与实践，掌握CI/CD工具链的使用","createTime":"2024-11-10 22:24:16","modifyTime":"2024-07-26 22:24:16"}
  ]

  static async save (trainingRecordForm: TrainingRecordForm): Promise<Result<void>> {
    console.log('trainingRecordApi save params', trainingRecordForm)
    const response: Response<void> = await mockApi.operateSuccessfully()
    return response.data
  }

  static async find (trainingRecordQueryForm: TrainingRecordQueryForm): Promise<Result<Page<TrainingRecord>>> {
    console.log('trainingRecordApi find params', trainingRecordQueryForm)
    const response: Response<Page<object>> = await mockApi.queryPageSuccessfully(trainingRecordApi.trainingRecords)
    return response.data
  }

  static async findById (id: number): Promise<Result<TrainingRecord>> {
    console.log('trainingRecordApi findById id', id)
    let target = {}
    for (const a of trainingRecordApi.trainingRecords) {
      if (a.id === id) {
        target = a
      }
    }
    const response: Response<TrainingRecord> = await mockApi.operateSuccessfullyWithData(target)
    return response.data
  }

  static async del (id: number): Promise<Result<void>> {
    console.log('trainingRecordApi del id', id)
    const response: Response<void> = await mockApi.operateSuccessfully()
    return response.data
  }
}
